package concurrent;

public class SynchronizedWait {

    public static void main(String[] args) {

        Object obj = new Object();

        Thread thread1 = new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (obj) {
                    try {
                        System.out.println("t1 start");
                        obj.wait();
                        System.out.println("t1 end");
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        });

        Thread thread2 = new Thread(new Runnable() {
            @Override
            public void run() {
                synchronized (obj) {
                    System.out.println("t2 start");
                    obj.notify();
                    System.out.println("t2 end");
                }
            }
        });

        thread1.start();
        thread2.start();
    }
}
